package com.llsydn.beijingnews.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import com.llsydn.beijingnews.base.BasePager;

import java.util.ArrayList;

/**
 * @author lilinshen
 * @title ContentFragment的适配器Adapter
 * @description 请填写相关描述
 * @date 2018/10/25 14:42
 */
public class ContentFragmentAdapter extends PagerAdapter {
    private final ArrayList<BasePager> basePagers;

    public ContentFragmentAdapter(ArrayList<BasePager> basePagers) {
        this.basePagers = basePagers;
    }

    @Override
    public int getCount() {
        return basePagers.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        BasePager basePager = basePagers.get(position);
        View rootView = basePager.rootview;
        // 调用各个页面的initData()方法
        // basePager.initData();
        container.addView(rootView);
        return rootView;
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}

